Project 3 and 89th program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: project 3
///File name: Project3.java
///Date Finished:2/1/2016
import java.util.Scanner;
import java.util.Random;
public class Project3
{
public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
Random r = new Random();
String choice;
int p1 = 1 + r.nextInt(10), p2 = 1 + r.nextInt(10), d1= 1 + r.nextInt(10), d2 = 1 + r.nextInt(10), pTotal, dTotal = d1+d2, hit;
System.out.println( "Blackjack!" );
System.out.println( "" );
System.out.println( "You get a " + p1 + " and a " + p2 + "." );
pTotal = p1 + p2;
System.out.println( "Your total is " + pTotal + "." );
System.out.println( "The dealer has a " + d1 + " showing, and a hidden card." );
System.out.println( "" );
System.out.print( "Would you like to \"hit\" or \"stay\"? " );
choice = kb.next();
while(choice.equals("hit") && pTotal <= 21)
{
hit = 2 + r.nextInt(10);
pTotal = pTotal + hit;
System.out.println( "You drew a " + hit + "." );
System.out.println( "Your total is " + pTotal + "." );
System.out.println( "" );
if(pTotal <= 21)
{
System.out.print( "Would you like to \"hit\" or \"stay\"? " );
choice = kb.next();
}
else
{
System.out.println( "You busted! The dealer wins!" );
}
}
if(pTotal <= 21)
{
System.out.println( "" );
System.out.println( "Dealer's turn." );
System.out.println( "His hidden card was a " + d2 + "." );
System.out.println( "His total is " + dTotal + "." );
}
while (pTotal <= 21 && dTotal <= 16)
{
hit = 2 + r.nextInt(10);
dTotal = dTotal + hit;
System.out.println( "" );
System.out.println( "The dealer chooses to hit." );
System.out.println( "He draws a " + hit + "." );
System.out.println( "His total is " + dTotal + "." );
System.out.println( "" );
}
if(dTotal > 21)
{
System.out.println( "Tye dealer busted. You Win!" );
}
else if(dTotal <= 21 && pTotal <= 21)
{
if(pTotal > dTotal)
System.out.println( "You Win" );
else if(pTotal < dTotal)
System.out.println( "You Lose" );
else
System.out.println( "It's a tie" );
}
}
}
Picture of the output